
# ----------------------------- 用户配置区 ---------------------------
SOFT_DIR?=soft/pxy
ROMSIZE=2048 
IRAMSIZE=256
XRAMSIZE=256
# -------------------------------------------------------------------




START_TIME := $(shell cat /proc/uptime | awk -F "." '{print $$1}') # Makefile进入，获取时间戳
OUTDIR=$(shell pwd)/build

all:sim showruntime

help:
	@echo "--------------------------------------------------------------------------------------------"
	@echo "make                               sim and showruntime"
	@echo "make SOFT_DIR=soft/blink           sim soft/blink"
	@echo "make sim                           sim"
	@echo "make wave                          watch wave"
	@echo "make SOFT_DIR=soft/blink sugar     compile blink soft, synth and config fpga to icesugar nano"
	@echo "---------------------------------------------------------------------------------------------"



sim: firmware
	@mkdir -p build
	@cp rtl/MCL51_CORE.hex build/
	iverilog -o build/tb.vvp -y ./rtl    rtl/tb.v 
	cd build && vvp tb.vvp -lxt2 

wave:
	cd build && gtkwave wave.lxt2 &

showruntime:
	@current_time=`cat /proc/uptime | awk -F "." '{print $$1}'`; \
	time_interval=`expr $${current_time} - $(START_TIME)`; \
	runtime=`date -u -d @$${time_interval} +%Hh:%Mm:%Ss`; \
	echo "runtime: $${runtime} "


firmware:
	@cd $(SOFT_DIR) && make ROMSIZE=$(ROMSIZE) XRAMSIZE=$(XRAMSIZE) IRAMSIZE=$(IRAMSIZE) firmware
	@bash isr.sh $(SOFT_DIR)

clean:
	@rm -rf build 


sugar:firmware 12M synth prog_flash showruntime

include icesugar.mk

